package com.wxl.micro.service.stock.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/stock")
public class StockController {

    @GetMapping("/query/{id}")
    @SentinelResource(value = "/query/{id}", fallback = "fallbackHandler")
//    @SentinelResource(value = "/query/{id}", blockHandler = "blockHandler")
//    @SentinelResource(value = "/query/{id}", fallback = "fallbackHandler", blockHandler = "blockHandler")
    public String query(@PathVariable String id){
        System.out.println("查询库存成功。id:" + id);
        return "查询库存成功。id:" + id;
    }

    @GetMapping("/get")
    public String get(){
        return "/stock/get";
    }



    // 限流
    public String blockHandler(String id, BlockException e) {
        e.printStackTrace();
        System.out.println("限流降级逻辑");
        return "限流降级逻辑";
    }

    // 熔断  接口出现异常 会走这里
    public String fallbackHandler(String id, Throwable e) {
        e.printStackTrace();
        System.out.println("熔断或接口出现异常降级逻辑");
        return "熔断或接口出现异常降级逻辑";
    }

}
